<template>
  <div class="login">
    <div class="login-title">后台管理系统</div>
    <div class="login-content">
      <div class="login-top">
        <div class="_title">用户登录</div>

        <div class="_welcome">欢迎登录XX管理平台</div>
      </div>
      <div class="login-form">
        <el-form ref="loginForm" :model="loginForm">
          <el-form-item prop="telephone">
            <el-input v-model.trim="loginForm.telephone" placeholder="请输入手机号"></el-input>
          </el-form-item>
          <!-- <el-form-item prop="code">
            <el-input v-model.trim="loginForm.code" placeholder="请输入验证码"></el-input>
            <div v-if="codeFlag" class="getCode" @click="codeFlag && getAuthCode()">获取验证码</div>
            <div v-else class="getCode disabled">{{totalTime}}s 后重新发送</div>
          </el-form-item> -->
          <el-form-item prop="password">
            <el-input v-model.trim="loginForm.password" placeholder="请输入密码"></el-input>
          </el-form-item>
          <el-form-item>
            <div class="login-form-submit" @click="loginUserAccount">立即登录</div>
          </el-form-item>
        </el-form>
        <!-- <avue-login :option="option" @submit="submit"></avue-login> -->
      </div>
    </div>
    <div
      class="login-bottom"
    >联系电话：400-632-8880 | 联系地址：东莞市松山湖高新技术产业开发区研发5路2号宏远新智汇3栋313，山东省潍坊市诸城市万兴路7号</div>
  </div>
</template>
<script>
import utils from "../../utils/index";
export default {
  data() {
    return {
      option: {

        time: 60,
        column: {
          username: {
            autocomplete: "off",
            rules: { required: true, message: "请输入手机号", trigger: "blur" }
          },
          password: {
            autocomplete: "off",
            rules: { required: true, message: "请输入密码", trigger: "blur" }
          }
        }
      },
      codeFlag: true,
      totalTime: 60,
      loginForm: {
        telephone: "",
        password: ""
      }
    };
  },
  methods: {
    getAuthCode() {
      let tel = this.loginForm.telephone;
      let RegPhone = new RegExp(
        /^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/
      );
      if (tel != "") {
        if (!RegPhone.test(tel)) {
          this.$message.error("手机号码格式不正确");
        }
        //获取验证码
        this.codeFlag = false;
        let clock = setInterval(() => {
          if (this.totalTime <= 0) {
            clearInterval(clock);
            this.codeFlag = true;
            this.totalTime = 60;
          } else {
            this.totalTime--;
          }
        }, 1000);
      } else {
        this.$message.error("请输入手机号码");
      }
    },
    loginUserAccount() {
      let form = this.loginForm;
      let RegPhone = new RegExp(
        /^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/
      ); //验证手机号
      if (form.telephone == "") {
        this.$message.error("请输入手机号码");
      } else if (!RegPhone.test(form.telephone)) {
        this.$message.error("手机号码格式不正确");
      } else if (form.password == "") {
        this.$message.error("请输入密码");
      } else {
        //登录

        if (true) {
          this.$message({
            message: "登录成功",
            type: "success"
          });
          const data = {};
          const user = {
            telephone: form.telephone,
            password: form.password,
            roleName: "管理员",
            username: "admin",
            token: "token"
          };

          utils.localStorage.set("token", user.token);
          utils.localStorage.set("user", user);
          this.$router.push("/");
        } else {
          this.$message.error("登录失败原因");
        }
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.login {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background-image: url("~@/assets/images/login/bg.png");
  background-repeat: no-repeat;
  background-size: 100% 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
}
.login-title {
  padding: 20px 0;
  font-size: 34px;
  color: $text-white;
  letter-spacing: 3px;
}
.login-content {
  width: 430px;
  height: 380px;
  box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  background-color: $bg-white;
  padding: 25px;
}
.login-bottom {
  font-size: 12px;
  color: $text-cnt;
  width: 100%;
  height: 320px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding: 40px 0;
}
.login-top {
  ._title {
    font-size: 34px;
    color: $color-df;
    text-align: center;
    margin-bottom: 20px;
  }
  ._welcome {
    display: flex;
    align-items: center;
    justify-content: center;
    color: $text-gray;
    font-size: 15px;
    &::before,
    &::after {
      content: "";
      display: block;
      flex: 1;
      width: 50px;
      height: 2px;
      background-color: $color-df;
    }
    &::after {
      margin-left: 10px;
    }
    &::before {
      margin-right: 10px;
    }
  }
}
.login-form {
  padding: 30px 5px;
  .getCode {
    width: 100px;
    height: 40px;
    line-height: 40px;
    background: $color-df;
    color: $text-white;
    border-radius: 0px 6px 6px 0px;
    position: absolute;
    right: 0;
    top: 0;
    font-size: 14px;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
    &.disabled {
      background-color: $text-light;
      color: $text-white;
    }
  }
  .login-form-submit {
    width: 100%;
    height: 50px;
    line-height: 50px;
    border-radius: 4px;
    background-color: $color-df;
    color: $text-white;
    font-size: 26px;
    text-align: center;
    cursor: pointer;
  }
}
</style>